package com.zyh.homework;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/*
    2.	接收从键盘输入的字符串格式的年龄，分数和入学时间，转换为整数、浮点数、日期类型，并在控制台输出
 */
public class Test2 {
    public static void main(String[] args) throws ParseException {
        System.out.println("请输入字符串：");
        String str = new Scanner(System.in).nextLine();
        if (str.contains("-")){
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = sdf1.parse(str);
            System.out.println("parse = " + parse);
        }
        else if (str.contains(".")){
            BigDecimal big1 = new BigDecimal(str);
            BigDecimal divide = big1.divide(new BigDecimal("1"), 2, BigDecimal.ROUND_HALF_UP);
            System.out.println("divide = " + divide);
        }
        else {
            int i = Integer.parseInt(str);
            System.out.println("i = " + i);
        }


    }
}
